/*
 * @Author: 屏幕适配
 * @Date: 2021-03-06 11:26:16
 * @LastEditTime: 2021-03-06 11:31:42
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /wordGame/assets/Script/core/common/CanvasAdapt.ts
 */
const { ccclass, property } = cc._decorator;
@ccclass
class CanvasAdapt extends cc.Component {
    onLoad() {
        cc.view.setResizeCallback(() => {
            this.adapt();
        })
        this.adapt();
    }
    adapt() {
        //屏幕比例
        let screenRatio = cc.winSize.width / cc.winSize.height;
        //设计图比例
        let designRatio = cc.Canvas.instance.designResolution.width / cc.Canvas.instance.designResolution.height;
        if (screenRatio < 1) {
            if (screenRatio < designRatio) {
                this.setFitWidth()
            } else {
                this.setFitHeight()
            }
        } else {
            this.setFitWidth()
        }
    }
    setFitHeight() {
        cc.Canvas.instance.fitHeight = true;
        cc.Canvas.instance.fitWidth = false;
    }
    setFitWidth() {
        cc.Canvas.instance.fitHeight = false;
        cc.Canvas.instance.fitWidth = true;
    }
}